//管理游戏中的角色

export default class Player {
    constructor(x, y,arrow) {
        this.x = x;
        this.y = y;
        this.arrow=arrow;
    }

    //在当前x，y坐标位置画出角色
    drawPlayer(ctx) {
        let img = new Image();
        img.src = './images/player.svg';
        console.log("position: " + this.x + " " + this.y)
            img.onload = () => {
                ctx.drawImage(img, 5 + 50 * this.x, 5 + 50 * this.y, img.width * 0.2, img.height * 0.2);
            }

    }

    drawCry(ctx) {
        let img = new Image();
        img.src = './images/cry.svg';
        console.log("position: " + this.x + " " + this.y)
            img.onload = () => {
                ctx.drawImage(img, 5 + 50 * this.x, 5 + 50 * this.y, img.width * 0.2, img.height * 0.2);
            }

    }

    drawHappyface(ctx) {
        let img = new Image();
        img.src = './images/happyface.svg';
        console.log("position: " + this.x + " " + this.y)
            img.onload = () => {
                ctx.drawImage(img, 5 + 50 * this.x, 5 + 50 * this.y, img.width * 0.2, img.height * 0.2);
            }

    }

    move(derection) {
        switch (derection) {
            case "up":
                if (this.y == 0) return;
                this.y--;
                break;
            case "down":
                if (this.y == 5) return;
                this.y++;
                break;
            case "left":
                if (this.x == 0) return;
                this.x--;
                break;
            case "right":
                if (this.x == 5) return;
                this.x++;
                break;
        }
    }
}

